package demo;

import utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author tongchen
 * @create 2022-12-27 13:54
 */
public class insert {
    //创建变量
   private static Connection connection;
   private static PreparedStatement statement;
   private static ResultSet resultSet;

    public static void main(String[] args) {
        //获取连接
        try {
            connection= DBUtils.getConnection();
            //定义sql
            String sql="insert into student values(null,?,?,?,?)";
            statement=connection.prepareStatement(sql);
            statement.setString(1,"10001");
            statement.setString(2,"gg");
            statement.setString(3,"bb");
            statement.setInt(4,2);
            //执行语句
            int i = statement.executeUpdate();
            if(i>0){
                System.out.println("执行成功");
            }
            else {
                System.out.println("执行失败");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        //释放资源
        DBUtils.closeResources(connection,statement,resultSet);
    }

}
